package action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

import service.service_admin.Service_Admin;
import service.service_public.Service_Public;
import service.service_search.Service_Search;
import tools.InterfacePropertyToolsPlaList;
import tools.PageBeanPlus;
import entitybean.l_sequence.EntityBeanL_Sequence;
import entitybean.oc_property_pla.EntityBean_Oc_Property_Pla;
import entitybean.oc_property_tools_pla.EntityBean_Oc_Property_Tools_Pla;
import form.PropertyToolsPlaForm;

public class Action_Oc_Property_Tools_Pla extends DispatchAction{
	private Service_Admin service_admin;
    private Service_Public service_public;
 	private Service_Search service_search;
	public Service_Admin getService_admin() {
		return service_admin;
	}

	public void setService_admin(Service_Admin service_admin) {
		this.service_admin = service_admin;
	}

	public Service_Public getService_public() {
		return service_public;
	}

	public void setService_public(Service_Public service_public) {
		this.service_public = service_public;
	}

	public Service_Search getService_search() {
		return service_search;
	}

	public void setService_search(Service_Search service_search) {
		this.service_search = service_search;
	}

	public ActionForward admin_init_oc_property_tools_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyToolsPlaForm actionForm = (PropertyToolsPlaForm) form;
		actionForm.setCurrentpage("1");
		actionForm.setPid(0);
		actionForm.setTools_name("");
		actionForm.setDef("");
		actionForm.setOver_time("");
		actionForm.setStart_time("");
		String sql = "select id,tools_name,def,pid  from OC_PROPERTY_TOOLS_PLA where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyToolsPlaList interfaceforresultsettolist = new InterfacePropertyToolsPlaList();
		List<EntityBean_Oc_Property_Tools_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);
		request.setAttribute("list", list);
		request.setAttribute("newslistform", actionForm);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}

	public ActionForward admin_load_oc_property_tools_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return null;
	}

	public ActionForward admin_add_oc_property_tools_pla(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		List<EntityBean_Oc_Property_Pla> propertypla=service_search.Find_EntityBean_Oc_Property_Pla();
		request.setAttribute("propertypla", propertypla);
		return mapping.findForward("success");
	}

	public ActionForward admin_insert_oc_property_tools_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyToolsPlaForm actionForm = (PropertyToolsPlaForm) form;
		Integer pid=actionForm.getPid();;
		String def=actionForm.getDef();
		String tools_name=actionForm.getTools_name();
		EntityBean_Oc_Property_Tools_Pla link=new EntityBean_Oc_Property_Tools_Pla();
        link.setDef(def);
        link.setPid(pid);
        link.setTools_name(tools_name);
		link.setDel("OFF");
		Integer i=0;
		EntityBeanL_Sequence entity=new EntityBeanL_Sequence();
		entity=this.service_public.Find_L_Sequence_By_seq_Name("SEQ_OC_PERPERY_TOOLS_PLA");
		i=entity.getSeq_Value()+1;
		entity.setSeq_Value(i);
		link.setId(i);
		this.service_public.Update_L_Sequence(entity);
		this.service_search.Insert_Oc_Property_Tools_Pla(link);
		System.out.println("初始化新闻模块");
		// 封装新闻查询的数据及表单
		PropertyToolsPlaForm goodForm = (PropertyToolsPlaForm) form;
		goodForm.setDef("");
		goodForm.setTools_name("");
		goodForm.setCurrentpage("1");
		goodForm.setOver_time("");
		goodForm.setStart_time("");
		String sql = "select id,tools_name,def,pid  from OC_PROPERTY_TOOLS_PLA where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyToolsPlaList interfaceforresultsettolist = new InterfacePropertyToolsPlaList();
		List<EntityBean_Oc_Property_Tools_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());


		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodForm);
		return mapping.findForward("success");
	}

	public ActionForward admin_delete_oc_property_tools_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyToolsPlaForm actionForm = (PropertyToolsPlaForm) form;
		String id = actionForm.getId();
		id = this.cut_tail(id);
		this.service_search.Delete_Oc_Property_Tools_Pla(id);

		String sql = "select id,tools_name,def,pid  from OC_PROPERTY_TOOLS_PLA where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyToolsPlaList interfaceforresultsettolist = new InterfacePropertyToolsPlaList();
		List<EntityBean_Oc_Property_Tools_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());

		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", actionForm);
		System.out.println("list.size()" + list.size());
		return mapping.findForward("success");
	}
	public ActionForward admin_update_init_property_tools_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyToolsPlaForm actionForm = (PropertyToolsPlaForm) form;
		String id=actionForm.getId();
		EntityBean_Oc_Property_Tools_Pla link=this.service_search.Find_EntityBean_Oc_Property_Tools_Pla(Integer.valueOf(id));
		request.setAttribute("PlaceView" , link); 
		List<EntityBean_Oc_Property_Pla> propertypla=service_search.Find_EntityBean_Oc_Property_Pla();
		request.setAttribute("propertypla", propertypla);
		return mapping.findForward("success");
	}

	public ActionForward admin_update_oc_property_tools_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyToolsPlaForm actionForm = (PropertyToolsPlaForm) form;
		Integer pid=actionForm.getPid();;
		String def=actionForm.getDef();
		String tools_name=actionForm.getTools_name();
		String id=actionForm.getId();
		EntityBean_Oc_Property_Tools_Pla link=new EntityBean_Oc_Property_Tools_Pla();
        link.setDef(def);
        link.setPid(pid);
        link.setTools_name(tools_name);
		link.setDel("OFF");
		link.setId(Integer.valueOf(id));
		this.service_search.Update_Oc_Property_Tools_Pla(link);
		PropertyToolsPlaForm goodForm = (PropertyToolsPlaForm) form;
		goodForm.setDef("");
		goodForm.setTools_name("");
		goodForm.setCurrentpage("1");
		goodForm.setOver_time("");
		goodForm.setStart_time("");
		String sql = "select id,tools_name,def,pid  from OC_PROPERTY_TOOLS_PLA where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyToolsPlaList interfaceforresultsettolist = new InterfacePropertyToolsPlaList();
		List<EntityBean_Oc_Property_Tools_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());


		request.setAttribute("pagebeanplus", pagebeanplus);// 设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", goodForm);
		return mapping.findForward("success");
	}

	public ActionForward admin_search_property_tools_pla(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		PropertyToolsPlaForm actionForm = (PropertyToolsPlaForm) form;
		String sql = "select id,tools_name,def,pid  from OC_PROPERTY_TOOLS_PLA where del='OFF' ORDER BY id DESC";
		PageBeanPlus pagebeanplus = new PageBeanPlus("oracle", "sql", sql,
				Integer.valueOf(actionForm.getRowcountperpage()), Integer
						.valueOf(actionForm.getCurrentpage()),
				"loadrichtext()");
		InterfacePropertyToolsPlaList interfaceforresultsettolist = new InterfacePropertyToolsPlaList();
		List<EntityBean_Oc_Property_Tools_Pla> list = interfaceforresultsettolist.ViewOc_News(pagebeanplus.getFormatqueryresultset());
		
		request.setAttribute("pagebeanplus", pagebeanplus);//设置传递到页面的数据
		request.setAttribute("list", list);
		request.setAttribute("newslistform", actionForm);
		System.out.println("list.size()"+list.size());
		return mapping.findForward("success");
	}

	private String cut_tail(String str) {
		String cut = str;
		if (str.endsWith(",")) {
			cut = cut.substring(0, cut.length() - 1);
		}
		return cut;
	}
}
